<!DOCTYPE html>
<html lang="en">

<head>
    <title>Vue.js Firebase example</title>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="style.css">
    <!-- Vue -->
    <script src="../dist/vue.js"></script>
    <!-- Firebase -->
    <script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
    <!-- VueFire -->
    <script src="https://cdn.jsdelivr.net/vuefire/1.0.1/vuefire.min.js"></script>
</head>

<body>
    <div id="app">

        <ul>
            <li class="user" v-for="user in users" transition>
                <span>{{user.name}} - {{user.email}}</span>
                <button v-on:click="removeUser(user)">X</button>
            </li>
        </ul>

        <form id="form" v-on:submit.prevent="addUser">
            <input v-model="newUser.name">
            <input v-model="newUser.email">
            <input type="submit" value="Add User">
        </form>

        <ul class="errors">
            <li v-show="!validation.name">Name cannot be empty.</li>
            <li v-show="!validation.email">Please provide a valid email address.</li>
        </ul>
        
    </div>
</body>
<script type="text/javascript">
// Firebase ref
var usersRef = new Firebase('https://vue-demo.firebaseIO.com/users')
var app = new Vue({
    data: {
        newUser: {
            name: '',
            email: ''
        }
    },
    firebase: {
        users: usersRef
    },

    computed: {
        validation: function() {
            return {
                name: !!this.newUser.name.trim(),
                email: emailRE.test(this.newUser.email)
            }
        }
    },

    // methods
    methods: {
        addUser: function() {

            console.log(this.newUser)
        }
    }
})
</script>

</html>
